package com.xiaoyu.lingdian.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.xiaoyu.lingdian.service.CoreMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xiaoyu.lingdian.core.mybatis.dao.MyBatisDAO;
import com.xiaoyu.lingdian.core.mybatis.page.Page;
import com.xiaoyu.lingdian.core.mybatis.page.PageRequest;
import com.xiaoyu.lingdian.entity.CoreMap;

@Service("coreMapService")
public class CoreMapServiceImpl implements CoreMapService {

	@Autowired
	private MyBatisDAO myBatisDAO;

	@Override
	public boolean insertCoreMap(CoreMap coreMap) {
		myBatisDAO.insert(coreMap);
		return true;
	}

	@Override
	public boolean updateCoreMap(CoreMap coreMap) {
		myBatisDAO.update(coreMap);
		return true;
	}

	@Override
	public boolean deleteCoreMap(CoreMap coreMap) {
		myBatisDAO.delete(coreMap);
		return true;
	}

	@Override
	public CoreMap getCoreMap(CoreMap coreMap) {
		return (CoreMap) myBatisDAO.findForObject(coreMap);
	}

	private static final String FIND_CORE_MAP_BY_CND = "findCoreMapByCnd";
	private static final String DELETE_CORE_MAP_BY_CND = "deleteCoreMapByCnd";
	
	@SuppressWarnings("unchecked")
	@Override
	public List<CoreMap> findCoreMapByCnd(String crmapLongitude, String crmapLatitude, String crmapUuid) {
		Map<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("crmapLongitude", crmapLongitude);
		hashMap.put("crmapLatitude", crmapLatitude);
		hashMap.put("crmapUuid", crmapUuid);
		return myBatisDAO.findForList(FIND_CORE_MAP_BY_CND, hashMap);
	}

	@Override
	public boolean deleteCoreMapByCnd(List<String> list) {
		Map<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("list", list);
		myBatisDAO.delete(DELETE_CORE_MAP_BY_CND, hashMap);
		return true;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Page<CoreMap> findCoreMapPage(String crmapLongitude, String crmapLatitude, String crmapUuid,
			int pageNum, int pageSize) {
		Map<String, Object> hashMap = new HashMap<String, Object>();
		hashMap.put("crmapLongitude", crmapLongitude);
		hashMap.put("crmapLatitude", crmapLatitude);
		hashMap.put("crmapUuid", crmapUuid);
		return myBatisDAO.findForPage(FIND_CORE_MAP_BY_CND, new PageRequest(pageNum, pageSize, hashMap));
	}

}